#ifndef VRP_LIGHTING_INCLUDED
#define VRP_LIGHTING_INCLUDED
#include "VInput.hlsl"
#include "VBRDF.hlsl"
#include "VGI.hlsl"
#include "../ShaderLib/VLights.hlsl"
#include "Shadow/Shadow.hlsl"



half3 VLightingPhysicallyBased(VBRDFData brdfData,
    Light light, half3 normalWS, half3 viewDirectionWS);
half3 VLightingPhysicallyBased(VBRDFData brdfData,
    half3 lightColor, half3 lightDirectionWS, half lightAttenuation,
    half3 normalWS, half3 viewDirectionWS);
void PhysicallyBaseDirectLighting(VBRDFData brdfData, Light light,
    out float3 directLighting, float3 viewDirectionWS, float3 normalWS);
half3 GetIlluminationDiffuse(VInputData inputData, Light light);
float3 ACESToneMapping(float3 x)
{
    float a = 2.51f;
    float b = 0.03f;
    float c = 2.43f;
    float d = 0.59f;
    float e = 0.14f;
    return saturate((x*(a*x+b))/(x*(c*x+d)+e));
}
half4 VUniversalFragmentPBR(VInputData inputData, VSurface surfaceData)
{
    VBRDFData brdfData;
    VInitializeBRDFData(surfaceData,inputData,brdfData);
    Light mainLight = GetMyMainLight();
    float3 directLighting;
    //IBL
    GI gi=getGI(inputData,brdfData);
    // (kD * diffuse + specular)
    PhysicallyBaseDirectLighting(brdfData,mainLight,directLighting,inputData.viewDirectionWS,inputData.normalWS);
    float shadow=GetMainLightShadowAtten(inputData.positionWS,inputData.normalWS);
    directLighting*=(1-shadow);
    #if defined(_NOIBL)
    gi.diffuse=float3(1,1,1);
    gi.specular=float3(0,0,0);
    #endif
    half3 col=directLighting+brdfData.diffuse*(gi.diffuse)+gi.specular;
    
    return half4(col,1);
}


void PhysicallyBaseDirectLighting(VBRDFData brdfData, Light light, out float3 directLighting,
    float3 viewDirectionWS, float3 normalWS)
{
    half3 lighting = light.color;
    
    #ifdef _CLEARCOAT
        float3 Term=clearCoatBRDF(brdfData,light,viewDirectionWS,normalWS);
    #else
        float3 Term=standardBRDF(brdfData,light,viewDirectionWS,normalWS);
    #endif
    
    directLighting=Term*lighting;
}



float3 GetLighting(VInputData surface, VBRDFData brdf, Light light, uint matCategory)
{
    float3 illuminance = light.color;

    float3 luminance;
    if (matCategory == 0)
    {
       
        
        //luminance = standardBRDF(surface.normalWS, light.direction, surface.viewDirectionWS, brdf) * illuminance;
        
    }
   
    
    return luminance;
}




#endif